<template>
    <el-breadcrumb separator="/" v-if="route.query.path" style="margin-top: 10px;">
        <el-breadcrumb-item @click="back()">返回上一级</el-breadcrumb-item>
        <el-breadcrumb-item @click="all()">
            <span style="cursor: pointer;"> 全部文件</span>
        </el-breadcrumb-item>
        <el-breadcrumb-item @click="currentfolder(item, index)" v-for="(item, index) in breadlist">
            <span style="cursor: pointer;"> {{ item.fileName }}</span>
        </el-breadcrumb-item>

    </el-breadcrumb>

</template>
<script setup>
import router from '@/router';
import service from '@/utils/Request';
import { ref } from 'vue';
import { useRoute } from 'vue-router';
const breadlist = ref([])
const emit = defineEmits(["getlist", "goback"])
const route = useRoute();
const back = () => {
    let pathlist = route.query.path.split("/");
    pathlist.splice(pathlist.length - 1, 1);
    router.push({
        path: "/index",
        query: {
            type: route.query.type,
            path: pathlist.join("/")
        }
    })
    emit("goback")
}
const all = () => {
    router.push({
        path: "/index",
        query: {
            type: route.query.type,

        }
    })
    emit("getlist")
}
const currentfolder = (item, index) => {
    breadlist.value.splice(index + 1, breadlist.value.length);
    console.log(breadlist.value)
    let path = [];


    breadlist.value.forEach(el => {
        path.push(el.fileId)

    })
    router.push({
        path: "/index",
        query: {
            type: route.query.type,
            path: path.join("/")
        }
    })
}
const getfolder = async () => {
    const res = await service.post("/file/getFolderInfo", {
        path: route.query.path
    });
    console.log(res)
    breadlist.value = res.data

}
const getfolder1 = async (path) => {
    const res = await service.post("/file/getFolderInfo", {
        path: path
    });
    console.log(res)
    breadlist.value = res.data

}
defineExpose({
    getfolder,
    getfolder1
})
</script>